<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DeepSeek模型测试</title>
    <style>
        body {
            font-family: 'PingFang SC', 'Inter', sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background: #f5f5f5;
        }
        .container {
            background: white;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #1e3a8a;
            text-align: center;
            margin-bottom: 30px;
        }
        .test-section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
        }
        .test-section h3 {
            color: #374151;
            margin-top: 0;
        }
        button {
            background: #3b82f6;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        button:hover {
            background: #2563eb;
        }
        button:disabled {
            background: #9ca3af;
            cursor: not-allowed;
        }
        .result {
            margin-top: 15px;
            padding: 15px;
            border-radius: 5px;
            white-space: pre-wrap;
            font-family: monospace;
            font-size: 14px;
        }
        .success {
            background: #d1fae5;
            border: 1px solid #10b981;
            color: #065f46;
        }
        .error {
            background: #fee2e2;
            border: 1px solid #ef4444;
            color: #991b1b;
        }
        .loading {
            background: #fef3c7;
            border: 1px solid #f59e0b;
            color: #92400e;
        }
        input, textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #d1d5db;
            border-radius: 5px;
            margin-bottom: 10px;
            font-family: inherit;
        }
        textarea {
            height: 100px;
            resize: vertical;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🧪 DeepSeek模型测试</h1>
        
        <!-- 基础测试 -->
        <div class="test-section">
            <h3>1. 基础调用测试</h3>
            <p>测试DeepSeek模型是否能正常响应</p>
            <button onclick="testBasic()">测试基础调用</button>
            <div id="basicResult"></div>
        </div>
        
        <!-- 角色扮演测试 -->
        <div class="test-section">
            <h3>2. 角色扮演测试</h3>
            <p>测试模型是否能以特定角色的语气进行对话</p>
            <input type="text" id="characterInput" placeholder="输入角色名称（如：柯南、莎士比亚）" value="柯南">
            <textarea id="roleplayPrompt" placeholder="输入测试内容">你好，请用柯南的语气和我对话</textarea>
            <button onclick="testRoleplay()">测试角色扮演</button>
            <div id="roleplayResult"></div>
        </div>
        
        <!-- 莎士比亚测试 -->
        <div class="test-section">
            <h3>3. 莎士比亚测试</h3>
            <p>测试莎士比亚角色的文学创作能力</p>
            <button onclick="testShakespeare()">测试莎士比亚</button>
            <div id="shakespeareResult"></div>
        </div>
        
        <!-- 自定义测试 -->
        <div class="test-section">
            <h3>4. 自定义测试</h3>
            <p>输入自定义的测试内容</p>
            <textarea id="customPrompt" placeholder="输入自定义测试内容">请介绍一下你自己</textarea>
            <button onclick="testCustom()">自定义测试</button>
            <div id="customResult"></div>
        </div>
    </div>

    <script>
        const BASE_URL = 'http://localhost:8080';
        
        function showResult(elementId, content, type = 'success') {
            const element = document.getElementById(elementId);
            element.innerHTML = content;
            element.className = `result ${type}`;
        }
        
        function showLoading(elementId) {
            showResult(elementId, '⏳ 正在测试中...', 'loading');
        }
        
        async function testBasic() {
            showLoading('basicResult');
            
            try {
                const response = await fetch(`${BASE_URL}/api/test/deepseek`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        prompt: '你好，请介绍一下你自己'
                    })
                });
                
                const data = await response.json();
                
                if (data.code === 200) {
                    showResult('basicResult', `✅ 测试成功！\n\n📝 响应内容:\n${data.data}`, 'success');
                } else {
                    showResult('basicResult', `❌ 测试失败: ${data.message}`, 'error');
                }
            } catch (error) {
                showResult('basicResult', `❌ 网络错误: ${error.message}`, 'error');
            }
        }
        
        async function testRoleplay() {
            showLoading('roleplayResult');
            
            const character = document.getElementById('characterInput').value;
            const prompt = document.getElementById('roleplayPrompt').value;
            
            if (!character || !prompt) {
                showResult('roleplayResult', '❌ 请输入角色名称和测试内容', 'error');
                return;
            }
            
            try {
                const response = await fetch(`${BASE_URL}/api/test/roleplay`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        character: character,
                        prompt: prompt
                    })
                });
                
                const data = await response.json();
                
                if (data.code === 200) {
                    showResult('roleplayResult', `✅ ${character}角色扮演测试成功！\n\n📝 ${character}回复:\n${data.data}`, 'success');
                } else {
                    showResult('roleplayResult', `❌ 测试失败: ${data.message}`, 'error');
                }
            } catch (error) {
                showResult('roleplayResult', `❌ 网络错误: ${error.message}`, 'error');
            }
        }
        
        async function testShakespeare() {
            showLoading('shakespeareResult');
            
            try {
                const response = await fetch(`${BASE_URL}/api/test/roleplay`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        character: '莎士比亚',
                        prompt: '请用莎士比亚的风格写一首关于友谊的十四行诗'
                    })
                });
                
                const data = await response.json();
                
                if (data.code === 200) {
                    showResult('shakespeareResult', `✅ 莎士比亚测试成功！\n\n📝 莎士比亚的诗:\n${data.data}`, 'success');
                } else {
                    showResult('shakespeareResult', `❌ 测试失败: ${data.message}`, 'error');
                }
            } catch (error) {
                showResult('shakespeareResult', `❌ 网络错误: ${error.message}`, 'error');
            }
        }
        
        async function testCustom() {
            showLoading('customResult');
            
            const prompt = document.getElementById('customPrompt').value;
            
            if (!prompt) {
                showResult('customResult', '❌ 请输入测试内容', 'error');
                return;
            }
            
            try {
                const response = await fetch(`${BASE_URL}/api/test/deepseek`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        prompt: prompt
                    })
                });
                
                const data = await response.json();
                
                if (data.code === 200) {
                    showResult('customResult', `✅ 自定义测试成功！\n\n📝 响应内容:\n${data.data}`, 'success');
                } else {
                    showResult('customResult', `❌ 测试失败: ${data.message}`, 'error');
                }
            } catch (error) {
                showResult('customResult', `❌ 网络错误: ${error.message}`, 'error');
            }
        }
    </script>
</body>
</html>
